# coding=utf8
from openpyxl import load_workbook
import os
import xlrd
from myself_robot.mytools.tools import *


class Handle:
    # def handle(self,filename=r"C:\Users\0000\PycharmProjects\Mytestes\myself\DDT\data\data.txt"):
    #
    #     with open(filename,'r',encoding='utf-8') as f:
    #         file=f.readlines()
    #         items=[]
    #         for i in range(1,len(file)):
    #             item=file[i].split()
    #             items.append(item)
    #         print(items)
    #         return items

    # def handle(self, filename=r"C:\Users\0000\PycharmProjects\Mytestes\myself\DDT\data\data.txt"):
    #     wk=load_workbook(r"C:\Users\0000\PycharmProjects\Mytestes\myself\DDT\data\data.xlsx")
    #     print(type(wk))
    #     print(wk["Sheet1"].max_column)
    #
    #     print(wk["Sheet1"].max_row)
    #     print(wk["Sheet1"].cell(1, 1).value)
    #     print(list(wk["Sheet1"].rows))
    #
    #     items=[]
    #     for item in list(wk["Sheet1"].rows)[0]:
    #         items.append(item.value)
    #     print(items)
    # def handle(self, filename=r"C:\Users\0000\PycharmProjects\Mytestes\myself\DDT\data\data.xlsx"):
    #     wkbook=load_workbook(os.path.abspath("..")+r"/data/data.xlsx")
    #     sheet=wkbook.worksheets[0]
    #
    #     data=[]
    #     # for i in range(1,sheet.max_row):
    #     # for item in list(sheet.rows)[1:]:
    #     #     data.append(item)
    #     # print(data)
    #     for row in sheet.rows:
    #         for cell in row:
    #             cell01 = cell.value  # 按行的维度输出值
    #             # print(cell01)
    #             print(cell.value,end=',')

    def handle(self, filename=pro_path() + r"\data\data.xls"):
        wk = xlrd.open_workbook(filename).sheet_by_index(0)
        mycaes = []
        for i in range(1, wk.nrows):
            row = wk.row_values(i)
            case = Case(row[0], row[1], row[2], self.deal_step(row[3]), row[4], row[5], row[3].replace("\n", ","))
            mycaes.append(case)
            # print(case.step)
        return mycaes

    def deal_step(self, step):
        step = step.replace("\n", ",")
        step = step.replace('=', "':'")
        step = step.replace(',', "','")
        newstep = "{'" + step + "'}"
        newstep = eval(newstep)
        # print(newstep)
        return newstep


class Case:
    def __init__(self, id, moudle, disc, step, exp, flog, report):
        self.id = id
        self.moudle = moudle
        self.disc = disc
        self.step = step
        self.flog = flog
        self.exp = exp
        self.report = report


if __name__ == '__main__':
    h = Handle()
    h.handle()
